import Vue from 'vue';
import VueRouter from 'vue-router';
import Login from '@/views/Login';

Vue.use(VueRouter);

const routes = [
    {
        path: '/',
        redirect: '/login',
    },
    {
        path: '/login',
        component: Login,
    },
    {
        path: '/index',
        component: () => import(/* webpackChunkName: "index" */ '../views/Index/Index.vue'),
        children: [
            {
                path: 'func',
                component: () => import(/* webpackChunkName: "func" */ '../views/Index/FuncCenter.vue'),
                meta: {
                    subTitle: '省点心',
                },
            },
            {
                path: 'usercenter',
                component: () => import(/* webpackChunkName: "usercenter" */ '../views/Index/UserCenter.vue'),
                children: [
                    {
                        path: 'userinfodetail',
                        component: () =>
                            import(/* webpackChunkName: "userinfodetail" */ '../views/Index/InfoDetail.vue'),
                        meta: {
                            subTitle: '个人信息',
                            showBack: true,
                            showBackHome: true,
                        },
                    },
                    {
                        path: 'versioninfo',
                        component: () =>
                            import(/* webpackChunkName: "versioninfo" */ '../views/Index/VersionDtail.vue'),
                        meta: {
                            subTitle: '版本信息',
                            showBack: true,
                            showBackHome: true,
                        },
                    },
                ],
            },
        ],
    },
    {
        path: '/logistics',
        component: () => import(/* webpackChunkName: "logistics" */ '../views/Logistics/Logistics.vue'),
        meta: {
            refresh: false,
            subTitle: '商品订单',
            showBack: true,
            showBackHome: true,
        },
    },
    {
        path: '/shippingorderinfo',
        component: () => import(/* webpackChunkName: "shippingorderinfo" */ '../views/Logistics/ShippingOrderInfo.vue'),
        meta: {
            keepDeath: true,
            subTitle: '订单信息',
            showBack: true,
        },
    },
    {
        path: '/evaluation',
        component: () => import(/* webpackChunkName: "evaluation" */ '../views/Logistics/Evaluation.vue'),
        meta: {
            keepDeath: true,
            subTitle: '评价',
            showBack: true,
        },
    },
    {
        path: '/newscenter',
        component: () => import(/* webpackChunkName: "newscenter" */ '../views/NewsCenter/NewsCenter.vue'),
        meta: {
            subTitle: '消息中心',
            showBack: true,
            ifSort: true,
        },
        children: [
            {
                path: 'newsdetail/:id',
                component: () => import(/* webpackChunkName: "newsdetail" */ '../views/NewsCenter/NewsDetail.vue'),
                meta: {
                    keepDeath: true,
                    subTitle: '消息详情',
                    showBack: true,
                },
            },
        ],
    },
    {
        path: '/wuliudan',
        component: () => import(/* webpackChunkName: "wuliudan" */ '../views/wuliudan/Index.vue'),
        meta: {
            subTitle: '快递单',
            showBack: true,
        },
        children: [
            {
                path: 'evaluationDetail/:id',
                component: () => import(/* webpackChunkName: "wuliudan" */ '../views/wuliudan/Detail.vue'),
                meta: {
                    subTitle: '快递单评价',
                    showBack: true,
                    showBackHome: true,
                },
            },
        ],
    },
    // {
    //   path: '/about',
    //   component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
    // },
];

const router = new VueRouter({
    // mode: 'history',
    base: process.env.BASE_URL,
    routes,
});

router.beforeEach((to, from, next) => {
    let str = /wuliudan\/evaluationDetail/;
    if (str.test(to.path)) {
        if (to.query.status) {
            to.meta.showBackHome = false;
        } else {
            to.meta.showBackHome = true;
        }
    }
    next();
});

export default router;
